package com.shop.user.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.user.dao.UserMapper;
import com.shop.user.pojo.User;
import com.shop.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("tkservice")
public class UserServiceImpl implements UserService {

    @Autowired   //自动装配对象
    private UserMapper userMapper;

    /**
     * 分页查询
     * @param realName
     * @param roleName
     * @param pageNum
     * @return
     */
    @Override
    public PageInfo<User> selectByFengYe(String realName, String roleName, Integer pageNum) {
        //保存当前页和每页显示的记录数
        PageHelper.startPage(pageNum,5);
        Map<String,Object> map=new HashMap<>();
        map.put("realName",realName);
        map.put("roleName",roleName);
        //调用dao层方法
        List<User> mgrs = userMapper.queryByPage(map);
        //通过pageInfo的构造方法赋值
        PageInfo<User> pageInfo=new PageInfo<>(mgrs);
        return pageInfo;
    }

    /**
     * 查询
     * @param account
     * @return
     */
    @Override
    public List<User> sel(String account) {
        return userMapper.sel(account);
    }

    /**
     * 添加
     * @param user
     * @return
     */
    @Override
    public int add(User user) {
        return userMapper.add(user);
    }


    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public boolean del(Integer id) {
        int del = userMapper.del(id);
        if (del>0){
            return true;
        }
        return false;
    }

    /**
     * 更新
     * @param user
     * @return
     */
    @Override
    public int upd(User user) {
        return userMapper.upd(user);
    }

    @Override
    public int count(String account) {
        return userMapper.count(account);
    }

}
